#!/usr/bin/env python
# -*- coding: utf-8 -*-
###################################################################
# Author: WangDonghao
# Date  : 2020.10
###################################################################

import os
from dayu_widgets.qt import *
from dayu_widgets.menu import MMenu
from dayu_widgets.check_box import MCheckBox
from dayu_widgets.label import MLabel
from dayu_widgets.push_button import MPushButton
from widgets.utils import MFetchDataThread
from dayu_widgets.combo_box import MComboBox
from dayu_widgets.message import MMessage
from dayu_widgets.radio_button import MRadioButton
from widgets.mq import thread


class ChangePriorityWin(QDialog):

    def __init__(self, parent=None, config={}):
        super(ChangePriorityWin, self).__init__(parent=parent)
        if not config.get('selected'):
            MMessage.error(parent=self.parent(), text=u'请选中锅再操作哦~', duration=3)
            return
            # raise
        # self.wok_name = config.get('selected')[0].get('code')
        self.setMinimumWidth(300)
        self.wok_detail = config
        self.wok_id = config.get('selected')[0].get('id')
        # get pandas
        self.priority_cb = MComboBox()
        self.priority_menu = MMenu()
        self.priority_menu.set_data([u'★★★', u'★★', u'★'])
        self.priority_cb.set_menu(self.priority_menu)

        main_lay = QVBoxLayout()
        self.setWindowTitle(u'更改优先级')

        lay = QHBoxLayout()
        lay.addWidget(MLabel(u'选择优先级:').warning().strong())
        lay.addWidget(self.priority_cb)
        self.ok_pb = MPushButton('OK')
        lay.addWidget(self.ok_pb)
        main_lay.addLayout(lay)
        self.setLayout(main_lay)

        self.update_thread = MFetchDataThread()
        self.update_thread.finished.connect(self.finish)
        self.ok_pb.clicked.connect(self.ok)
        self.msg = None

    def ok(self):
        priority = len(self.priority_cb.currentText())
        self.setEnabled(False)
        MMessage.config(10)
        self.msg = MMessage.loading(text=u'正在执行操作...', parent=self.parent())
        self.update_thread.mode = 'update'
        self.update_thread.data = [os.environ.get('WOK_ENTITY'), self.wok_id, {'priority': priority}]
        self.update_thread.start()
        # pass

    def finish(self):
        if self.msg:
            self.msg.close()
        MMessage.config(3)
        MMessage.success(u'操作成功！', self.parent())
        self.close()
        self.parent().current_page.parse_config()


if __name__ == '__main__':
    pass

